﻿#include "FITKAbaLoadPressure.h"


Interface::FITKAbaAbstractLoad::FITKAbaLoadType Interface::FITKAbaLoadPressure::getLoadType() const
{
    return Interface::FITKAbaAbstractLoad::FITKAbaLoadType::Pressure;
}

bool Interface::FITKAbaLoadPressure::copy(FITKAbstractDataObject *obj)
{
    bool ok = FITKAbaAbstractLoad::copy(obj);
    if (!ok)
        return false;
    FITKAbaLoadPressure* p = dynamic_cast<FITKAbaLoadPressure*>(obj);
    if (p == nullptr)
        return false;
    //拷贝数据
    m_data = p->m_data;
    return true;
}

bool Interface::FITKAbaLoadPressure::isModifiedInStep(int stepId) const
{
    //获取数据是否修改
    if (m_modifiedDatas.contains(stepId))
        return true;
    return false;
}

void Interface::FITKAbaLoadPressure::activeStateChanged()
{
    //激活状态发生变化时，数据的调整
    if (m_deactiveStepId == -1)
        return;
    //访问当前算例的分析步管理器，获取分析步顺序id列表。
    QVector<int> stepIds = this->getStepIds();
    int index = stepIds.indexOf(m_deactiveStepId);
    if (index == -1)
        return;
    for (int i = index; i < stepIds.count(); ++i)
    {
        int id = stepIds[i];
        if (m_modifiedDatas.contains(id))
            m_modifiedDatas.remove(id);
    }
}

double Interface::FITKAbaLoadPressure::getPressure(int stepId)
{
    //获取创建载荷所在分析步中的载荷数据
    return this->getDataInStep(stepId).getPreesure();
}

void Interface::FITKAbaLoadPressure::setPressure(double value, int stepId)
{
    if (stepId <= 0)
        m_data.setPressure(value);
    else
    {
        if (!m_modifiedDatas.contains(stepId))
            m_modifiedDatas[stepId] = this->getDataInStep(stepId);
        m_modifiedDatas[stepId].setPressure(value);
    }
}

int Interface::FITKAbaLoadPressure::getAmplitudeId(int stepId)
{
    return this->getDataInStep(stepId).getAmplitudeId();
}

void Interface::FITKAbaLoadPressure::setAmplitudeId(int id, int stepId)
{
    if (stepId <= 0)
        m_data.setAmplitudeId(id);
    else
    {
        if (!m_modifiedDatas.contains(stepId))
            m_modifiedDatas[stepId] = this->getDataInStep(stepId);
        m_modifiedDatas[stepId].setAmplitudeId(id);
    }
}

Interface::PressureData Interface::FITKAbaLoadPressure::getDataInStep(int stepId)
{
    if (stepId <= 0)
        return m_data;
    if (m_modifiedDatas.contains(stepId))
        return m_modifiedDatas[stepId];
    QVector<int> stepIds = this->getStepIds();
    int createdStepIndex = stepIds.indexOf(m_createdStepId);
    int stepIndex = stepIds.indexOf(stepId);
    if (!(createdStepIndex >= 0 && createdStepIndex < stepIds.size()))
        return m_data;
    if (!(stepIndex >= 0 && stepIndex < stepIds.size()))
        return m_data;
    for (int i = stepIndex; i >= createdStepIndex; --i)
    {
        int id = stepIds.at(i);
        if (m_modifiedDatas.contains(id))
            return m_modifiedDatas[id];
    }
    return m_data;
}

double Interface::PressureData::getPreesure() const
{
    return m_value;
}

void Interface::PressureData::setPressure(double value)
{
    m_value = value;
}

int Interface::PressureData::getAmplitudeId() const
{
    return m_m_AmplitudeId;
}

void Interface::PressureData::setAmplitudeId(int id)
{
    m_m_AmplitudeId = id;
}
